package event;

import java.util.Hashtable;

import pool.bean.Property_details_Bean;
import property.Codegenerator;
import property.Property;
import utility.ConvertToLower;
import utility.Input;
import utility.MessageGenerator;
import sms.SmsBuffer;
import User.Uservalidation;
import control.Control;
import control.RequestParameter;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class  Personcodegenerator implements Event
{
	String PERSONCODE="Personcode";
	String ITEM="Item";
	DBManager database;
	GetIdName gin;
	String type;
	String masterid;
	String MESSAGE;
	String  userid;
	String Request="";
	String Name;
	boolean flag;
	String TYPE;
	String MOBILENO="mobileno";
	String username;
	String userResponse ="Response : You have added \"TYPE\" And the Personcode for \"master\" is : " ;
	String Responce="Welcome to Open source Pool U Have Been successfully added as TYPE And U can give u r order through sms. Your personcode is : ";
		
	public boolean getResult() 
	{	 
		return flag;
	}
	
	public void initializationData(DBManager database) 
	{	 
		this.database = new DBManager();
		this.database.getConnect();
		gin = new GetIdName(database);
		PERSONCODE = gin.getId(PERSONCODE);
		MOBILENO = gin.getId(MOBILENO);
	}
	public void setObject(String Object) 
	{		
		
		String newPersonCode;
		Codegenerator code = new Codegenerator(database); 
		newPersonCode= code.RegisterItem(PERSONCODE);
		
		if(!newPersonCode.equals("Error"))
		{
			Hashtable<Object, Object>table= new Hashtable<Object, Object>();
			Responce = Responce.replace("TYPE",gin.getItem(TYPE));
			userResponse = userResponse.replace("TYPE",gin.getItem(TYPE));
			userResponse = userResponse.replace("master",Name);
			userResponse = userResponse+newPersonCode;
			Responce = Responce+newPersonCode;
			try 
			{
				Hashtable<Object, Object>hashtable1 = new Hashtable<Object, Object>();
				PERSONCODE=gin.getItem(PERSONCODE);
				hashtable1.put("pid", PERSONCODE);
				hashtable1.put("pv", newPersonCode);
				hashtable1.put("mid", Name);
				userid = "+911234567891";
				Uservalidation getpass = new Uservalidation(database);
				String password = getpass.getPasword(userid);
				Property_details_Bean propertydetailbean=new Property_details_Bean();
				propertydetailbean.setTable("property_details");
				RequestParameter req = new RequestParameter();
				req.setUsername(userid);
				req.setMessage("System Message");
				req.setPassword(password);
				req.setRequest("property_details");
				req.setProcess("add");
				propertydetailbean.setDBManager(database);
				propertydetailbean.setReqParam(req);
				propertydetailbean.setOldPropertyHash(hashtable1);
				propertydetailbean.insert();
				flag=propertydetailbean.getResult();
			}
			catch (Exception e) 
			{
				e.printStackTrace();
			}
		}
	
	}
	public static void main(String[] args) 
	{
		
		Personcodegenerator personcode = new Personcodegenerator();
		DBManager database = new  DBManager();
		database.getConnect();
		personcode.initializationData(database);
		personcode.setObject("");
		personcode.getResult();	
	}
	
	public void SetData(String Product, String type, String masterid,String userid, String Process) 
	{	
				
		this.type = type;
		this.masterid = masterid;
		this.userid = userid;
		username = userid;
		
		
	}
	
	public boolean afterAdd() 
	{	
		return getResult();
	}
	
	public boolean afterDel() 
	{	
		return false;
	}
	
	public boolean afterMod() 
	{	
		return false;
	}
	
	public boolean afterView() 
	{	
		return false;
	} 
}
